
<?php $this->beginClip('pagetitle'); ?>代理商<?php $this->endClip(); ?>

<div class="am-g" style="padding: 10px">
    <div style="width: 75%;position: fixed;left: 12%;background-color: rgba(234,233,254,0.5);">

        <div class="am-alert am-alert-danger" id="my-alert" style="display: none">
            <p>开始日期应小于结束日期！</p>
        </div>
        <div class="am-g">
            <div class="am-u-sm-5">
                <button type="button" class="am-btn am-btn-default am-margin-right" name="start_time" id="my-start">开始日期</button><span id="my-startDate"></span>
            </div>
            <div class="am-u-sm-5">
                <button type="button" class="am-btn am-btn-default am-margin-right" name="end_time" id="my-end">结束日期</button><span id="my-endDate"></span>
            </div>
            <div class="am-u-sm-2">
                <button type="button" class="am-btn am-btn-primary" id="my-search">搜索</button>
            </div>
        </div>
    </div>

    <table class="am-table am-table-bordered am-table-radius am-table-striped am-table-hover" style="margin-top: 5%">
        <thead>
        <tr>

            <th>ID</th>
            <th>代理商名称</th>
            <th>代理商等级</th>
            <th>银行卡号</th>
            <th>开户行</th>
            <th>身份证号</th>
            <th>联系电话</th>
            <th>开户数*20</th>
            <th>红包数*0.1</th>
            <th>交易额</th>
            <th>交易笔数</th>
        </tr>
        </thead>
        <tbody id="agent_data">
        <?php foreach ($agents as $agnet):?>
            <tr>
                <td>
                    <?= $agnet['id_agent']?>
                </td>
                <td>
                    <?= str_repeat('&nbsp;',$agnet['level']*5).'|--'.$agnet['name']?>
                    <a href="/tool/agnetDetail?agent_id=<?= $agnet['id_agent']?>" class="am-btn am-btn-primary am-round">明细</a>
                </td>
                <td>
                    <?= $agnet['level']?>
                </td>
                <td><?= $agnet['card_no']?></td>
                <td><?= $agnet['bank_name']?></td>
                <td><?= $agnet['id_number']?></td>
                <td><?= $agnet['phone']?></td>
                <td><?= $agnet['merchent_count']?></td>
                <td><?= round($agnet['trade_data'][0]['discount_sum']/100,2)?></td>
                <td><?= round($agnet['trade_data'][0]['amount_due_sum']/100,2)?></td>
                <td><?= $agnet['trade_data'][0]['trade_sum']?></td>
            </tr>
        <?php endforeach;?>
        </tbody>
    </table>
</div>

<script>
    $(function() {
        var nowTemp = new Date();
        var nowDay = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0).valueOf();
        var yestoDay = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate()-1, 0, 0, 0, 0).valueOf();
        var nowMoth = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), 1, 0, 0, 0, 0).valueOf();
        var nowYear = new Date(nowTemp.getFullYear(), 0, 1, 0, 0, 0, 0).valueOf();

        var startDate = new Date(nowYear, nowMoth, yestoDay);
        var endDate = new Date(nowMoth, nowMoth, nowDay);
        var $alert = $('#my-alert');
        var flag = false;
        $('#my-start').datepicker().
        on('changeDate.datepicker.amui', function(event) {
            if (event.date.valueOf() > endDate.valueOf()) {
                $alert.find('p').text('开始日期应小于结束日期！').end().show();
                flag = false;
            } else {
                $alert.hide();
                startDate = new Date(event.date);
                $('#my-startDate').text($('#my-start').data('date'));

            }
            $(this).datepicker('close');
        });

        $('#my-end').datepicker().
        on('changeDate.datepicker.amui', function(event) {
            if (event.date.valueOf() < startDate.valueOf()) {
                $alert.find('p').text('结束日期应大于开始日期！').end().show();
                flag = false;
            } else {
                $alert.hide();
                endDate = new Date(event.date);
                $('#my-endDate').text($('#my-end').data('date'));
                flag = true;
            }
            $(this).datepicker('close');
        });

        $('#my-search').click(function(){
            if(flag){
                $.ajax({
                    url:'/tool/AgentAjax',
                    type:'post',
                    data:{'start_time':$('#my-start').data('date'),'end_time':$('#my-end').data('date')},
                    success:function(res){

                        $('#agent_data').html(res);
                    }
                });
            }
        });
    });
</script>